package com.mdd.admin.controller.reply;

import com.mdd.admin.config.aop.Log;
import com.mdd.admin.service.reply.IOfficialAccountReplyService;
import com.mdd.admin.validate.reply.OfficialAccountReplyParam;
import com.mdd.admin.validate.common.PageParam;
import com.mdd.admin.vo.reply.OfficialAccountReplyListVo;
import com.mdd.admin.vo.reply.OfficialAccountReplyDetailVo;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validator.annotation.IDMust;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 微信公众号自动回复管理
 */
@RestController
@RequestMapping("api/reply")
public class OfficialAccountReplyController {

    @Resource
    IOfficialAccountReplyService iOfficialAccountReplyService;

    /**
     * 微信公众号自动回复列表
     *
     * @param pageParam 分页参数
     * @param params 搜索参数
     * @return Object
     */
    @GetMapping("/list")
    public Object list(@Validated PageParam pageParam,
                       @RequestParam Map<String, String> params) {
        PageResult<OfficialAccountReplyListVo> list = iOfficialAccountReplyService.list(pageParam, params);
        return AjaxResult.success(list);
    }
    /**
     * 微信公众号自动回复详情
     *
     * @param id 主键ID
     * @return Object
     */
    @GetMapping("/detail")
    public Object detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        OfficialAccountReplyDetailVo detail = iOfficialAccountReplyService.detail(id);
        return AjaxResult.success(detail);
    }

    /**
     * 微信公众号自动回复新增
     *
     * @param officialAccountReplyParam 参数
     * @return Object
     */
    @Log(title = "微信公众号自动回复新增")
    @PostMapping("/add")
    public Object add(@Validated(value = OfficialAccountReplyParam.create.class) @RequestBody OfficialAccountReplyParam officialAccountReplyParam) {
        iOfficialAccountReplyService.add(officialAccountReplyParam);
        return AjaxResult.success();
    }

    /**
     * 微信公众号自动回复编辑
     *
     * @param officialAccountReplyParam 参数
     * @return Object
     */
    @Log(title = "微信公众号自动回复编辑")
    @PostMapping("/edit")
    public Object edit(@Validated(value = OfficialAccountReplyParam.update.class) @RequestBody OfficialAccountReplyParam officialAccountReplyParam) {
        iOfficialAccountReplyService.edit(officialAccountReplyParam);
        return AjaxResult.success();
    }

    /**
     * 微信公众号自动回复删除
     *
     * @param officialAccountReplyParam 参数
     * @return Object
     */
    @Log(title = "微信公众号自动回复删除")
    @PostMapping("/del")
    public Object del(@Validated(value = OfficialAccountReplyParam.delete.class) @RequestBody OfficialAccountReplyParam officialAccountReplyParam) {
       // iOfficialAccountReplyService.del(officialAccountReplyParam.getId());
        return AjaxResult.success();
    }

}
